﻿// -----------------------------------------------------------------------
// <copyright file="SaveLoadScores.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace BeatEmUp
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public static class SaveLoadScores
    {        

        public static void SaveScoresListToFile(ref string scoresFileName, ref List<int> scoresList)
        {
            FileStream file = File.Open(scoresFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            StreamWriter saver = new StreamWriter(file);
            
            for (int i = 0; i < scoresList.Count; i++)
            {
                string tmp = "" + scoresList[i];
                saver.WriteLine(tmp);
            }
            saver.Close();
            file.Close();
        }

        public static void LoadScoresListFromFile(ref string scoresFileName, ref List<int> scoresList)
        {
            if (File.Exists(scoresFileName))
            {

                FileStream file = File.Open(scoresFileName, FileMode.Open, FileAccess.Read);
                StreamReader reader = new StreamReader(file);

                scoresList.Clear();

                string value = "";
                while (!reader.EndOfStream)
                {
                    value = reader.ReadLine();
                    scoresList.Add(int.Parse(value));
                }

                file.Close();
            }
            else
            {
                File.Create(scoresFileName);
            }
        }
       
    }
}
